package org.itworks.biodev.gui;

import java.awt.event.*;
import java.sql.*;

import javax.swing.*;

import org.itworks.biodev.gui.panels.*;
import org.itworks.biodev.model.*;

public class MainWindowView extends JFrame {
	
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 4644830523777858135L;
	private JTabbedPane mainTabbedPane;
	private JPanel customersPanel;
    private JPanel giftsPanel;
    private JPanel homePanel;
    private JPanel meetingsPanel;
    private JPanel ordersPanel;
    private JPanel parametersPanel;
    private JPanel productsPanel;
    private JPanel salariesPanel;
    private JPanel salesPanel;
    
    
    public MainWindowView() {
    	initComponents();
    	initHandlers();
    }
    
    private void initHandlers() {
    	this.addWindowListener(new WindowListener() {

			@Override
			public void windowActivated(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void windowClosed(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void windowClosing(WindowEvent e) {
				// TODO Auto-generated method stub
				try {
					BiodevDatabase.commit();
					BiodevDatabase.close();
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}

			@Override
			public void windowDeactivated(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void windowDeiconified(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void windowIconified(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void windowOpened(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
    		
    	});
    }
    
    
    private void initComponents() {
    	
    	//setResizable(false);
    	setTitle("Biodev");
    	
    	mainTabbedPane = new javax.swing.JTabbedPane();
    	//homePanel = new javax.swing.JPanel();
    	homePanel = HomePanelView.getInstance(this);
    	//meetingsPanel = new javax.swing.JPanel();
    	meetingsPanel = MeetingsPanelView.getInstance(this);
    	
    	//salesPanel = new javax.swing.JPanel();
    	salesPanel = SalesPanelView.getInstance(this);
    	
    	
    	ordersPanel = OrdersPanelView.getInstance(this);
    	
    	//salariesPanel = new javax.swing.JPanel();
    	salariesPanel = SalariesPanelView.getInstance(this);
    	
    	//productsPanel = new javax.swing.JPanel();
    	productsPanel = ProductsPanelView.getInstance(this);
    	
    	giftsPanel = new javax.swing.JPanel();
    	
    	
    	//customersPanel = new javax.swing.JPanel();
    	customersPanel = CustomersPanelView.getInstance(this);
    			
    	//parametersPanel = new javax.swing.JPanel();
    	parametersPanel = ParametersPanelView.getInstance(this);
    	setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    	/*
    	javax.swing.GroupLayout homePanelLayout = new javax.swing.GroupLayout(homePanel);
    	homePanel.setLayout(homePanelLayout);
    	homePanelLayout.setHorizontalGroup(
    	   homePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    	   .addGap(0, 711, Short.MAX_VALUE)
    	);
    	homePanelLayout.setVerticalGroup(
    	   homePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    	   .addGap(0, 320, Short.MAX_VALUE)
    	);
    	*/

    	mainTabbedPane.addTab("Accueil", homePanel);

    	/*
        javax.swing.GroupLayout meetingsPanelLayout = new javax.swing.GroupLayout(meetingsPanel);
        meetingsPanel.setLayout(meetingsPanelLayout);
        meetingsPanelLayout.setHorizontalGroup(
            meetingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1100, Short.MAX_VALUE)
        );
        meetingsPanelLayout.setVerticalGroup(
            meetingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 734, Short.MAX_VALUE)
        );
        */

        mainTabbedPane.addTab("Reunions", meetingsPanel);

        /*
        javax.swing.GroupLayout salesPanelLayout = new javax.swing.GroupLayout(salesPanel);
        salesPanel.setLayout(salesPanelLayout);
        salesPanelLayout.setHorizontalGroup(
            salesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1100, Short.MAX_VALUE)
        );
        salesPanelLayout.setVerticalGroup(
            salesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 734, Short.MAX_VALUE)
        );
        */

        mainTabbedPane.addTab("Ventes", salesPanel);

        /*
        javax.swing.GroupLayout salaryPanelLayout = new javax.swing.GroupLayout(salaryPanel);
        salaryPanel.setLayout(salaryPanelLayout);
        salaryPanelLayout.setHorizontalGroup(
            salaryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1100, Short.MAX_VALUE)
        );
        salaryPanelLayout.setVerticalGroup(
            salaryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 734, Short.MAX_VALUE)
        );
        */

        mainTabbedPane.addTab("Salaires", salariesPanel);

        /*javax.swing.GroupLayout productsPanelLayout = new javax.swing.GroupLayout(productsPanel);
        productsPanel.setLayout(productsPanelLayout);
        productsPanelLayout.setHorizontalGroup(
            productsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1100, Short.MAX_VALUE)
        );
        productsPanelLayout.setVerticalGroup(
            productsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 734, Short.MAX_VALUE)
        );*/

        mainTabbedPane.addTab("Produits", productsPanel);

        /*
        javax.swing.GroupLayout giftsPanelLayout = new javax.swing.GroupLayout(giftsPanel);
        giftsPanel.setLayout(giftsPanelLayout);
        giftsPanelLayout.setHorizontalGroup(
            giftsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1100, Short.MAX_VALUE)
        );
        giftsPanelLayout.setVerticalGroup(
            giftsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 734, Short.MAX_VALUE)
        );
		*/
        mainTabbedPane.addTab("Cadeaux & Avantages", giftsPanel);

        /*
        javax.swing.GroupLayout customersPanelLayout = new javax.swing.GroupLayout(customersPanel);
        customersPanel.setLayout(customersPanelLayout);
        customersPanelLayout.setHorizontalGroup(
            customersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1100, Short.MAX_VALUE)
        );
        customersPanelLayout.setVerticalGroup(
            customersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 734, Short.MAX_VALUE)
        );
        */

        mainTabbedPane.addTab("Clients", customersPanel);

       /* javax.swing.GroupLayout ordersPanelLayout = new javax.swing.GroupLayout(ordersPanel);
        ordersPanel.setLayout(ordersPanelLayout);
        ordersPanelLayout.setHorizontalGroup(
            ordersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1100, Short.MAX_VALUE)
        );
        ordersPanelLayout.setVerticalGroup(
            ordersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 734, Short.MAX_VALUE)
        );*/

        mainTabbedPane.addTab("Commandes Fournisseur", ordersPanel);

        /*javax.swing.GroupLayout parametersPanelLayout = new javax.swing.GroupLayout(parametersPanel);
        parametersPanel.setLayout(parametersPanelLayout);
        parametersPanelLayout.setHorizontalGroup(
            parametersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1100, Short.MAX_VALUE)
        );
        parametersPanelLayout.setVerticalGroup(
            parametersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 734, Short.MAX_VALUE)
        );*/

        mainTabbedPane.addTab("Parametres", parametersPanel);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(mainTabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 1105, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(mainTabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 762, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }
    
    public void selectMeetingsTab() {
    	this.mainTabbedPane.setSelectedComponent(meetingsPanel);
    }
    
    public void selectSalesTab() {
    	this.mainTabbedPane.setSelectedComponent(salesPanel);
    }
    
    public void selectSalariesTab() {
    	this.mainTabbedPane.setSelectedComponent(salariesPanel);
    }
    
    public void selectProductsTab() {
    	this.mainTabbedPane.setSelectedComponent(productsPanel);
    }
    
    public void selectGiftsTab() {
    	this.mainTabbedPane.setSelectedComponent(giftsPanel);
    }
    
    public void selectCustomersTab() {
    	this.mainTabbedPane.setSelectedComponent(customersPanel);
    }
    
    public void selectParametersTab() {
    	this.mainTabbedPane.setSelectedComponent(parametersPanel);
    }
    
    public void selectOrdersSupplierTab() {
    	this.mainTabbedPane.setSelectedComponent(ordersPanel);
    }

}
